package com.yonghui;

import java.lang.ref.ReferenceQueue;
import java.lang.ref.SoftReference;
import java.util.concurrent.TimeUnit;

/**
 * 强引用与软引用OOM
 */
public class TestOOM {

    public static void main(String[] args) {
        //强引用
//        testStrongReference();
        //软引用
        testSoftReference();
    }

    private static void testStrongReference(){
        byte[] arr0=new byte[1024*1024*1];
        byte[] arr1=new byte[1024*1024*1];
        byte[] arr2=new byte[1024*1024*1];
        System.out.println("执行完毕");
    }

    private static void testSoftReference(){
        ReferenceQueue queue=new ReferenceQueue();
        SoftReference sf0=new SoftReference(new byte[1024*1024*1],queue);
        SoftReference sf1=new SoftReference(new byte[1024*1024*1],queue);
        SoftReference sf2=new SoftReference(new byte[1024*1024*1],queue);
        System.out.println("执行完毕");
    }
}
